/* Import Afriat from matlab */

insheet using garp/Afriatp22.txt, clear
save garp/Afriatp2.dta, replace
insheet using garp/Afriatp23.txt, clear
append using garp/Afriatp2.dta
save garp/Afriatp2.dta, replace
insheet using garp/Afriatp26.txt, clear
append using garp/Afriatp2.dta
save garp/Afriatp2.dta, replace

ren v1 subject
ren v2 Afriatp2
ren v3 flagp2
ren v4 vpairsp2
label var Afriatp2 "Afriat index combining Part 1 CBC + part 2 (rule or CBC)"
label var flagp2 "GARP violations combining Part 1 CBC + part 2 (rule or CBC)"
save garp/Afriatp2.dta, replace

insheet using garp/Afriat2.txt, clear
save garp/Afriat.dta, replace
insheet using garp/Afriat3.txt, clear
append using garp/Afriat.dta
save garp/Afriat.dta, replace
insheet using garp/Afriat6.txt, clear
append using garp/Afriat.dta

ren v1 subject
ren v2 Afriatr
ren v3 Afriatd
ren v4 Afriatc
ren v5 flagr
ren v6 flagd
ren v7 flagc
ren v8 vpairsr
ren v9 vpairsd
ren v10 vpairsc
label var Afriatr "Afriat index in Part 1 rule allocations"
label var Afriatd "Afriat index in Part 1 case-by-case allocations"
label var Afriatc "Afriat index in Part 1 rule + case-by-case"
label var flagr "Flag of whether violate garp in rule"
label var flagd "Flag of whether violate garp in CBC"
label var flagc "Flag of whether violate garp in rule+CBC"
sort subject
save garp/Afriat.dta, replace

gen AfriatDrop = Afriatd - Afriatc
label var AfriatDrop "Drop in CBC Afriat index when adding rule allocations"

merge 1:1 subject using garp/Afriatp2.dta, nogenerate
merge 1:m subject using subjects.dta, nogenerate
save comb, replace

/* clean up */
rm garp/Afriat.dta
rm garp/Afriatp2.dta
